package com.mkyong;

import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.Map;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.AjaxBehaviorEvent;
import javax.faces.event.ValueChangeEvent;

@ManagedBean(name="country")
@SessionScoped
public class CountryBean implements Serializable {
	private static final long serialVersionUID = 1L;
	private String name;
	private int count;
	private static Map<String,String> countries;
	private String localeCode = "en";
	
	static {
		countries = new LinkedHashMap<String,String>();
		countries.put("United Kingdom", "en");
		countries.put("French", "fr");
		countries.put("German", "de");
		countries.put("China", "zh_CN");
	}

	public int getCount() {
		return count;
	}
	
	public void setCount(int count) {
		this.count = count;
	}
	
	public String getName() {
		return name;
	}


	public void setName(String name) {
		this.name = name;
	}


	public Map<String, String> getCountriesInMap() {
		return countries;
	}


	public String getLocaleCode() {
		return localeCode;
	}

	public void setLocaleCode(String localeCode) {
		this.localeCode = localeCode;
	}
	
	public void countryLocaleCodeChanged(ValueChangeEvent e) {
		localeCode = e.getNewValue().toString();
		System.out.println("new localeCode = " + localeCode);
	}
	
	public void ajaxCountryLocaleCodeChanged(AjaxBehaviorEvent event) {
		name = "hello";
		localeCode = "Japan";
	}
	
	public void countListener(AjaxBehaviorEvent event) {
		count = name.length();
	}
	
	
	
}
